package com.usabb.service.impl;

import com.google.common.collect.Lists;
import com.ifast.common.base.CoreServiceImpl;
import com.usabb.dao.PromiseRelationDao;
import com.usabb.domain.PromiseRelationDO;
import com.usabb.service.PromiseRelationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <pre>
 * 标签关联表
 * </pre>
 * <small> 2019-08-19 18:03:26 | Aron</small>
 */
@Slf4j
@Service
public class PromiseRelationServiceImpl extends CoreServiceImpl<PromiseRelationDao, PromiseRelationDO> implements PromiseRelationService {

    @Override
    public void addAll(Long bizId, Long[] promiseIds) {
        if (ArrayUtils.isEmpty(promiseIds)) {
            log.info("PromiseRelation add - ids is null ");
            return;
        }

        List<PromiseRelationDO> relationDOList = Lists.newArrayListWithCapacity(promiseIds.length);
        for (Long promiseId : promiseIds) {
            relationDOList.add(PromiseRelationDO.of(bizId, promiseId));
        }
        this.insertBatch(relationDOList);
    }

    @Override
    public List<PromiseRelationDO> getAllByBizId(Long bizId) {
        Map<String, Object> paramMap = new HashMap<>(1);
        paramMap.put("bizId", bizId);

        return this.selectByMap(paramMap);
    }


}
